/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nadesicoi

import groovy.sql.*
/**
 *
 * @author Octavio
 */
@grails.persistence.Entity
class Precios implements Serializable {
    int        id
    int        id_articulo
    int        id_almacen
    double     costo
    double     descuento
    double     utilidad
    //Articulos  articulo
    int        version

    static mapping = {
        table      'precios'
        id composite:['id_articulo', 'id_almacen']
        //id column: 'id_articulo'
        //static   belongsTo = Articulos
        //articulo column:'id_articulo'
        //version  false
    }
}


class PreciosFunciones {
    static def modificar(Map cambios, db, IDAlmacen, IDArticulo) {
        cambios.each { clv, val ->
            try {
                db.executeUpdate("UPDATE precios SET $clv = ? WHERE id_almacen = ? AND id_articulo = ?", [val,IDAlmacen,IDArticulo])
            } catch(Exception e) {
                throw e
            }
        }

    }
}

